package com.xuecheng.teaching.controller;

import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.WorkDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.WorkVo;
import com.xuecheng.teaching.domain.Work;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.teaching.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * <p>
 * 作业前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class WorkController {

    @Autowired
    private WorkService  workService;

    //分页查询
    @PostMapping("/work/list")
    public ResponseResult<WorkVo> findByPage(PageRequest pageRequest,@RequestBody(required = false) WorkDto workDto){
        return workService.findByPage(pageRequest,workDto);
    }

    //新增或更新试卷
    @PostMapping("/work")
    public ResponseResult saveOrUpdateWork(@RequestBody WorkDto workDto){
        return workService.saveOrUpdateWork(workDto);
    }

    //根据id查询试卷
    @GetMapping("/work/{workId}")
    public ResponseResult<WorkVo> findWorkById(@PathVariable Long workId){
        return workService.findWorkById(workId);
    }

    //根据id删除试卷
    @DeleteMapping("/work/{workId}")
    public ResponseResult deleteWork(@PathVariable Long workId){
        return workService.deleteWork(workId);
    }
}
